package util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test2 {

    public static void main(String args[]){

//    private static final String REGX_START_SEC = "([期初][(（][0-9]*\\*+年\\*+月[）)])";
//    private static final String REGX_START_SEC_ONE = "([初期]+[(（][0-9]*\\*+年\\*+月[）)])";
//    private static final String REGX_START_SEC_TWO = "([开始]+[(（][0-9]*\\*+年\\*+月[）)])";
//    private static final Pattern P_START_SEC = Pattern.compile(REGX_START_SEC);
//    private static final Pattern P_START_SEC_ONE = Pattern.compile(REGX_START_SEC_ONE);
//    private static final Pattern P_START_SEC_TWO = Pattern.compile(REGX_START_SEC_TWO);

//    private static final String SHENJI_STARTENDDATE = "审计期初（20\\*\\*年\\*\\*月）[\\\\与](审计)?期末（20\\*\\*年\\*\\*月）";
//    private static final String REGX_WORK_ENDMONTH = "截止任职结束月（20\\*\\*年\\*\\*月）"
//    复制截止任职结束月规则，新增截止审计结束月规则
//    private static final String REGX_END_SEC = "([期末][(（][0-9]*\\*+年\\*+月[）)])";
//    private static final String REGX_END_SEC_ONE = "([结束]+[(（][0-9]*\\*+年\\*+月[）)])";
//    private static final Pattern P_END_SEC = Pattern.compile(REGX_END_SEC);
//    private static final Pattern P_END_SEC_ONE = Pattern.compile(REGX_END_SEC_ONE);




//        if (P_START_SEC.matcher(desFileName).find()){
//            desFileName = desFileName.replaceAll(REGX_START_SEC,"期初("+startDateStr+")");
//        }
//        if (P_START_SEC_ONE.matcher(desFileName).find()){
//            desFileName = desFileName.replaceAll(REGX_START_SEC_ONE,"初期("+startDateStr+")");
//        }
//        if (P_START_SEC_TWO.matcher(desFileName).find()){
//            desFileName = desFileName.replaceAll(REGX_START_SEC_TWO,"开始("+startDateStr+")");
//        }
        //期末日期填充
//        if (P_WORK_DATE.matcher(desFileName).find()) {
//            desFileName = desFileName.replaceAll(REGX_WORK_DATE, "期间（" + startDateStr + "-" + endDateStr + "）");
//        }
//
//        if (P_WORK_START_END_DATE.matcher(desFileName).find()) {
//            desFileName = desFileName.replaceAll(REGX_WORK_STARTENDDATE, "任职期初（" + startDateStr + "）\\\\期末（" + endDateStr + "）");
//        }

//        if (P_WORK_END_MONTH.matcher(desFileName).find()) {
//            desFileName = desFileName.replaceAll(REGX_WORK_ENDMONTH, "截止任职结束月（" + endDateStr + "）");
//        }
//
//
//        if (P_SHENJI_START_END_DATE.matcher(desFileName).find()) {
//            desFileName = desFileName.replaceAll(SHENJI_STARTENDDATE, "审计期初（" + startDateStr + "）\\\\期末（" + endDateStr + "）");
//        }

//        if (P_SHENJI_END_MONTH.matcher(desFileName).find()) {
//            desFileName = desFileName.replaceAll(SHENJI_ENDMONTH, "截止审计结束月（" + endDateStr + "）");
//        }

//        String qijian = "[\\uff08]\\*+[\\u5e74]\\*+[\\u6708]-\\*+[\\u5e74]\\*+[\\u6708][\\uff09]";
//        String secName = "([\\*]+[同志])";
//        String secName1 = "([\\*]+[领导])";
//        String section = "([(（][0-9]*\\*+年\\*+月[-~～—至到][0-9]*\\*+年\\*+月[）)])";
        //13.1、期初（20**年**月）\任职月初（20**年**月）各部门负责人名单
        String desFileName = "任职月初（20**年**月）\\期末（20**年**月）各部门负责人名单";

        String startDateStr = "2020年07月";
        String endDateStr = "2021年08月";

        String REGX_TIME_START = "[(（][0-9]*\\*+年\\*+月";
        String REGX_TIME_END = "[0-9]*\\*+年\\*+月[）)]";
        String REGX_PERIOD = "([(（][0-9]*\\*+年\\*+月[-~～—至到][0-9]*\\*+年\\*+月[）)])";
        Pattern P_PERIOD = Pattern.compile(REGX_PERIOD);
        //复制任职期初规则，新增审计期初规则
        String REGX_TIME = "[(（][0-9]*\\*+年\\*+月[）)]";
        String REGX_START = "(((月初)|(期初)|(初期)|(开始))+[\\W]*[(（][0-9]*\\*+年\\*+月[）)])";
        String REGX_END = "(((期末)|(结束))+[\\W]*[(（][0-9]*\\*+年\\*+月[）)])";
        final Pattern P_START = Pattern.compile(REGX_START);
        Pattern P_END = Pattern.compile(REGX_END);
        //冲突字符串（开始结束）
        String REGX_STARTANDEND = "((开始结束)|(期初期末)[\\W]*[(（][0-9]*\\*+年\\*+月[）)])";
        Pattern P_STARTANDEND = Pattern.compile(REGX_STARTANDEND);

        //未匹配到任何关键字
        String REGX_NOT_ALL = "([\\W]*[(（][0-9]*\\*+年\\*+月[）)])";
        Pattern P_NOT_ALL = Pattern.compile(REGX_NOT_ALL);

        //期间日期填充
        if (P_PERIOD.matcher(desFileName).find()){
            desFileName = desFileName.replaceAll(REGX_TIME_START, "(" + startDateStr);
            desFileName = desFileName.replaceAll(REGX_TIME_END,endDateStr + ")");
        }
        //冲突字符填充
        if(P_STARTANDEND.matcher(desFileName).find()){
            desFileName = desFileName.replaceAll(REGX_STARTANDEND,"开始结束("+endDateStr+")");
        }
        //期初日期填充
        Matcher matcher = P_START.matcher(desFileName);
        if (matcher.find()){
            String matcherStr = matcher.group();
            int indexStart = desFileName.indexOf(matcherStr);
            int endStart = indexStart+matcherStr.length();
            String tempStr = desFileName.substring(indexStart,endStart).replaceAll(REGX_TIME,"("+startDateStr+")");
            desFileName = desFileName.substring(0,indexStart) + tempStr + desFileName.substring(endStart);
        }

        //期末日期填充
        matcher = P_END.matcher(desFileName);
        if (matcher.find()){
            String matcherStr = matcher.group();
            int indexStart = desFileName.indexOf(matcherStr);
            int endStart = indexStart+matcherStr.length();
            String tempStr = desFileName.substring(indexStart,endStart).replaceAll(REGX_TIME,"("+endDateStr+")");
            desFileName = desFileName.substring(0,indexStart) + tempStr + desFileName.substring(endStart);
        }

        //未匹配到任何关键字
        matcher = P_NOT_ALL.matcher(desFileName);
        if (matcher.find()){
            String matcherStr = matcher.group();
            int indexStart = desFileName.indexOf(matcherStr);
            int endStart = indexStart+matcherStr.length();
            String tempStr = desFileName.substring(indexStart,endStart).replaceAll(REGX_TIME,"("+endDateStr+")");
            desFileName = desFileName.substring(0,indexStart) + tempStr + desFileName.substring(endStart);
        }

        System.out.println(desFileName);
    }
}
